package com.itheima.homework14;
/*
有一个存放牛奶的箱子，送奶工将牛奶放入箱子，
而用户从箱子中获取到牛奶，假设箱子只能存储一瓶牛奶，
请编写程序模拟牛奶的存储和获取过程。
 */
public class Box {

    private boolean state = false;
    private int milk;

    //存奶操作
    public synchronized void put(int milk) throws Exception {

        if (state == true) {
            wait();
        }

        this.milk = milk;
        System.out.println("送奶工送奶,送奶次数:" + milk);

        state = true;

        notifyAll();
    }


    public synchronized void get() throws Exception {

        if (state == false) {
            wait();
        }

        System.out.println("消费者取奶,取奶次数:" + milk);

        state = false;

        notifyAll();
    }

}
